<template>
  <div>
    <el-form>
      <el-form-item>
        <el-input v-model="user.username" placeholder="请输入内容"></el-input>
      </el-form-item>
      <el-form-item>
        <el-input
          v-model="user.password"
          type="password"
          placeholder="请输入内容"
        ></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="danger" @click.native="btn">立即登录</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
export default {
  // 组件名称
  name: "demo",
  // 组件参数 接收来自父组件的数据
  props: [],
  // 局部注册的组件
  components: {},
  // 组件状态值
  data() {
    return {
      user: {
        username: "",
        password: "",
      },
    };
  },
  // 计算属性
  computed: {},
  // 侦听器
  watch: {},
  // 组件方法
  methods: {
    btn() {
      if (this.username == "" || this.password == "") {
        this.$message.error("请输入密码或账号");
        return false;
      }
      this.$store.commit("login", this.user);
      this.$router.go(-1);
      this.$message.success(
        `登录成功,欢迎你:${this.$store.state.user.username}`
      );
    },
  },
  //生命周期
  created() {},
  mounted() {},
};
</script> 

<style scoped lang="scss">
.el-form {
  width: 30%;
  margin: auto;
  border: 1px solid rgb(66, 8, 228);
  padding: 30px;
  border-radius: 20px;
  .el-button {
    width: 100%;
  }
}
</style>
